package JVM;


import java.util.Scanner;

public class tset1 {

    public static int n=0;
    public static int m=0;
    public static int max=0;
    public static int[] res=null;
    //贪心算法
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int[][] path=new int[1001][1001];
        int nn=s.nextInt();
        int mm=s.nextInt();
        n=nn;
        m=mm;
        int u=0;
        int v=0;
        while (s.hasNext()){
            u=s.nextInt();
            v=s.nextInt();
            int p=s.nextInt();
            path[u][v]=p;
            path[v][u]=p;
        }
        res=new int[u];
        for (int i=1;i<=u;i++){
            for (int j=i+1;j<=u;j++){
                int[] arr=new int[n];
                dfs(i,path,arr,i,j);
            }
        }
        int m=0;
        for (int i=0;i< res.length;i++){
            m=Math.max(m,res[i]);
        }
        System.out.println(m);
    }

    public static void dfs(int pos,int[][] path,int[] arr,int start,int end){

            if (pos==end){
                res[start-1]=max;
                max=0;
            }

            arr[pos]=1;
            for (int i=1;i<=n;i++){
                if (arr[i]==0&&path[pos][i]>0) {
                    max=Math.max(path[pos][i],max);
                    dfs(i, path, arr, start, end);
                }
            }

            arr[pos]=0;
    }
}

